package util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Iterator;

public class varList {
	public ArrayList<varInfo> ArgList = new ArrayList<varInfo>();
	public FileOutputStream out = null;
	public PrintStream p = null;

	public varList() {
		// super();
	}

	public void Init() {
		File file = new File("VarList.txt");
		if (file.exists())
			file.delete();
		try {
			out = new FileOutputStream(file);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		p = new PrintStream(out);
	}

	public void addArgInfo(varInfo info) {
		ArgList.add(info);
	}

	public void addArgInfo(int index, varInfo info) {
		ArgList.add(index, info);
	}

	public varInfo get(int index) {
		return (varInfo) ArgList.get(index);
	}

	public varInfo remove(int index) {
		return ArgList.remove(index - 1);
	}

	public void clear() {
		ArgList.clear();
		varInfo.size = 0;
	}

	public void printArgTable() {
		Iterator<varInfo> itr = ArgList.iterator();
		try {
			while (itr.hasNext()) {
				varInfo tmp = (varInfo) itr.next();
				p.println(tmp.toString());
				// System.out.println(tmp.toString());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public boolean checkRepeat(varInfo info) {
		boolean flag = false;
		Iterator<varInfo> itr = ArgList.iterator();
		while (itr.hasNext()) {
			varInfo tmp = (varInfo) itr.next();
			if (tmp.getName().equals(info.getName())) {
				flag = true;
				// throw new TokenMgrError("Error: Ignoring invalid lexical state : . State
				// unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);
				break;
			}
		}
		return flag;
	}

	public boolean checkUndefined(String name) {
		boolean flag = true;
		Iterator<varInfo> itr = ArgList.iterator();
		while (itr.hasNext()) {
			varInfo tmp = (varInfo) itr.next();
			if (tmp.getName().equals(name)) {
				flag = false;
				break;
			}
		}
		return flag;
	}

}
